package com.woniuxy.project115.kaer.mall.consumer;

import com.woniuxy.project115.kaer.mall.entity.ProductOrderInfo;
import com.woniuxy.project115.kaer.mall.mapper.ProductOrderInfoMapper;
import com.woniuxy.project115.kaer.mall.service.EvaluationService;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class CheckIsEvaluateConsumer {
    @Resource
    private EvaluationService evaluationService;
    @Resource
    private ProductOrderInfoMapper productOrderInfoMapper;
    @RabbitListener(bindings = @QueueBinding(
            value=@Queue(name="check_isEvaluate_queue"),
            exchange = @Exchange(name="de3"),
            key = "check_isEvaluate"
    ))
    @RabbitHandler
    public void checkOrder(String orderNum)throws Exception{
        System.out.println("自动评价:"+orderNum);
        ProductOrderInfo orderInfo = productOrderInfoMapper.selectById(orderNum);
       if (orderInfo.getOrderState().equals("待评价")){
           evaluationService.autoEvaluate(orderNum);
       }
    }
}
